package com.apes.framework.plugin.form.parser.element;

import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import com.apes.framework.plugin.form.FormConst;
import com.apes.framework.plugin.form.parser.node.FormNodeParser;
import com.apes.framework.util.LogicalUtil;
import com.apes.framework.util.Tools;
import org.springframework.stereotype.Component;


/**
 * 功能：组件生命周期钩子函数
 *
 * @author xul
 * @create 2018-09-06 16:30
 */
@Component
public class LifecycleElementParser implements ApesElementParser<ApesElement, String> {
    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"lifecycle"};

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return FormNodeParser.domain;
    }

    /**
     * 功能：可解析的元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    /**
     * 功能：元素解析
     *
     * @param element
     */
    @Override
    public String parse(ApesElement element) {
        String name = element.getAttributes().get("name");
        if (Tools.isNull(name) || LogicalUtil.notIn(name, FormConst.lifecycle) || Tools.isNull(element.getText()))
            return null;
        return element.getText();
    }
}